<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.soeasy.util.UserUtil"%>
<%@page import="com.feib.soeasy.action.Soez9009ActionBean"%>
<%@page import="com.feib.soeasy.model.UserActionLog"%>

<%
	Soez9009ActionBean actionBean =(Soez9009ActionBean) request.getAttribute("actionBean");
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><%=UserUtil.getCurrentMenuItemName() %></title>
	<script type="text/javascript" src="<c:url value='/scripts/jquery/jquery.bgiframe-2.1.2.js'/>"></script>
	
	<script type="text/javascript">
	<!--	
	$(document).ready(function() {

		$('#doQueryBtn').click(function() {
			var errMsg = "";			
			var groupNo = $('#qryFormatDefinition\\.group\\.groupNo').val();
			
			var formatDefinitionPk = $('#qryFormatDefinition\\.formatDefinitionPk').val();
						
			if (null == groupNo || 0 == groupNo.length){
				errMsg = errMsg + "業者代號 是必要欄位<br/>";
			}//2011/06/16 jeff Gu  start   修正    業者代號不存在時 查詢錯誤問題
			else if (12 != groupNo.length){
				errMsg = errMsg + "業者代號 為固定長度12碼<br/>";
			}
			//2011/06/16 jeff Gu  end   修正    業者代號不存在時 查詢錯誤問題
			
			
			if (null == formatDefinitionPk || 0 == formatDefinitionPk.length){
				errMsg = errMsg + "收款名稱 是必要欄位<br/>";
			}
						
			if (0 != errMsg.length){
				$("#ajaxErrorMessageDiv").html(errMsg);
				$("#ajaxErrorMessageDiv" ).dialog({  
					title:'請修正下列錯誤' 
					,width: 300
					, resizable: false
					, modal: true
					, buttons: {
						Ok: function() {
							$( this ).dialog( "close" );
						}
					}
				});
				return false;
			}
			
			$('#hidden\\.qryFormatDefinition\\.formatDefinitionPk').val(formatDefinitionPk);
			doQueryAction(1);
		});
		
		
		$('#doSaveColumnDefinitionBtn').click(function() {
			var errMsg = "";
			$("[id^='tr-header-']").each(function(i){
				var idx = this.id.substring(10);
				var nextId = parseInt(idx, 10) + 1;
				var titleId = '#editHeaderColumnDefinitions\\['+idx+'\\]\\.columnTitle';
				var title = $(titleId).val();
				
				var columnNameId = '#editHeaderColumnDefinitions\\['+idx+'\\]\\.columnName';
				var columnName = $(columnNameId).val();
				
				var beginIndexId = '#editHeaderColumnDefinitions\\['+idx+'\\]\\.beginIndex';
				var beginIndex = $(beginIndexId).val();
				var beginIndexEmpty = (null == beginIndex || 0 == beginIndex.length);
				
				var endIndexId = '#editHeaderColumnDefinitions\\['+idx+'\\]\\.endIndex';
				var endIndex = $(endIndexId).val();
				var endIndexEmpty = (null == endIndex || 0 == endIndex.length);
				
				if (null == title || 0 == title.length){
					errMsg = errMsg + "表頭序號["+ nextId + "]欄位名稱 是必要欄位<br/>";
				}
	
				if (null == columnName || 0 == columnName.length){
					errMsg = errMsg + "表頭序號["+ nextId + "]對應欄位 是必要欄位<br/>";
				}
				
				if ( beginIndexEmpty && endIndexEmpty){
					
				}
				else if (beginIndexEmpty && !endIndexEmpty){
					errMsg = errMsg + "表頭序號["+ nextId + "]資料位置請輸入完整起迄<br/>";
				}
				else if (!beginIndexEmpty && endIndexEmpty){
					errMsg = errMsg + "表頭序號["+ nextId + "]資料位置請輸入完整起迄<br/>";					
				}
				else{
					var tmp1 = parseInt(beginIndex, 10);
					if (isNaN(tmp1)){
						errMsg = errMsg + "表頭序號["+ nextId + "]資料位置(起)值須為整數<br/>";
					}
					else
						beginIndex = tmp1;
					
					var tmp2 = parseInt(endIndex, 10);
					if (isNaN(tmp2)){
						errMsg = errMsg + "表頭序號["+ nextId + "]資料位置(迄)值須為整數<br/>";
					}
					else
						endIndex = tmp2;
					
					if (!isNaN(tmp1) && !isNaN(tmp2)){
						if (endIndex - beginIndex < 0)
							errMsg = errMsg + "表頭序號["+ nextId + "]資料位置起迄錯誤<br/>";
					}
				}			
				
			});
			
			$("[id^='tr-item-']").each(function(i){
				var idx = this.id.substring(8);
				var nextId = parseInt(idx, 10) + 1;
				var titleId = '#editItemColumnDefinitions\\['+idx+'\\]\\.columnTitle';
				var title = $(titleId).val();
				
				var columnNameId = '#editItemColumnDefinitions\\['+idx+'\\]\\.columnName';
				var columnName = $(columnNameId).val();
				
				var beginIndexId = '#editItemColumnDefinitions\\['+idx+'\\]\\.beginIndex';
				var beginIndex = $(beginIndexId).val();
				var beginIndexEmpty = (null == beginIndex || 0 == beginIndex.length);
				
				var endIndexId = '#editItemColumnDefinitions\\['+idx+'\\]\\.endIndex';
				var endIndex = $(endIndexId).val();
				var endIndexEmpty = (null == endIndex || 0 == endIndex.length);
				
				if (null == title || 0 == title.length){
					errMsg = errMsg + "表單序號["+ nextId + "]欄位名稱 是必要欄位<br/>";
				}
	
				if (null == columnName || 0 == columnName.length){
					errMsg = errMsg + "表單序號["+ nextId + "]對應欄位 是必要欄位<br/>";
				}
				
				if ( beginIndexEmpty && endIndexEmpty){
					
				}
				else if (beginIndexEmpty && !endIndexEmpty){
					errMsg = errMsg + "表單序號["+ nextId + "]資料位置請輸入完整起迄<br/>";
				}
				else if (!beginIndexEmpty && endIndexEmpty){
					errMsg = errMsg + "表單序號["+ nextId + "]資料位置請輸入完整起迄<br/>";					
				}
				else{
					var tmp1 = parseInt(beginIndex, 10);
					if (isNaN(tmp1)){
						errMsg = errMsg + "表單序號["+ nextId + "]資料位置(起)值須為整數<br/>";
					}
					else
						beginIndex = tmp1;
					
					var tmp2 = parseInt(endIndex, 10);
					if (isNaN(tmp2)){
						errMsg = errMsg + "表單序號["+ nextId + "]資料位置(迄)值須為整數<br/>";
					}
					else
						endIndex = tmp2;
					
					if (!isNaN(tmp1) && !isNaN(tmp2)){
						if (endIndex - beginIndex < 0)
							errMsg = errMsg + "表單序號["+ nextId + "]資料位置起迄錯誤<br/>";
					}
				}			
			});
			
			if (0 != errMsg.length){
				$("#ajaxErrorMessageDiv").html(errMsg);
				$("#ajaxErrorMessageDiv" ).dialog({  
					title:'請修正下列錯誤' 
					,width: 300
					, resizable: false
					, modal: true
					, buttons: {
						Ok: function() {
							$( this ).dialog( "close" );
						}
					}
				});
				return false;
			}
			return true;
			
		});
		
		$('#doAddHeaderColumnBtn').click(function() {
			addTableRow( $('#headerColumnDefinitions'), true);
		});
		
		$('#doAddItemColumnBtn').click(function() {
			addTableRow( $('#itemColumnDefinitions'), false);
		});
		
		$('#printBtn2').click(function() {
			divPrint('queryResultDiv');
		});
		
		
		$('#findGroupNoImg').click(function() {
			var groupNo = $('#qryFormatDefinition\\.group\\.groupNo').val();
			
			if (null != groupNo && 0 != groupNo.length){
				var tmpGroupNo = parseInt(groupNo,10);
				if(! isNaN(tmpGroupNo)){
					$('#hidden\\.qryGroup\\.groupNo').val(groupNo);
					$('#hidden\\.qryGroup\\.groupName').val('');
					$('#qryGroup\\.groupNo').val(groupNo);
					$('#qryGroup\\.groupName').val('');
				}
				else{
					$('#hidden\\.qryGroup\\.groupNo').val('');
					$('#hidden\\.qryGroup\\.groupName').val(groupNo);
					$('#qryGroup\\.groupNo').val('');
					$('#qryGroup\\.groupName').val(groupNo);
					$("#queryGroupResultDiv").html('');
				}
				
				$("#findGroupDiv" ).dialog({  
					title:'帳單業者查詢' 
					, width: 600
					, resizable: true
					, modal: true
				});
				
				$('#doAjaxQueryGroupsBtn').click();
			}
			else{
				$('#hidden\\.qryGroup\\.groupNo').val('');
				$('#hidden\\.qryGroup\\.groupName').val('');
				$('#qryGroup\\.groupNo').val('');
				$('#qryGroup\\.groupName').val('');
				$("#queryGroupResultDiv").html('');
				$("#findGroupDiv" ).dialog({  
					title:'帳單業者查詢' 
					, width: 600
					, resizable: true
					, modal: true
				});
			}
		});
		
		$('#doAjaxQueryGroupsBtn').click(function() {
			var groupNo = $('#qryGroup\\.groupNo').val();
			var groupName = $('#qryGroup\\.groupName').val();
			$("#queryGroupResultDiv").html('');

			$('#hidden\\.qryGroup\\.groupNo').val(groupNo);
			$('#hidden\\.qryGroup\\.groupName').val(groupName);
			doQueryGroupAction(1);
			
		});
		
		$('#doAjaxCloseGroupsBtn').click(function() {
			$("#findGroupDiv" ).dialog( "close" );
		});

		
		$('#qryFormatDefinition\\.group\\.groupNo').change(function() {
			var groupNo = $('#qryFormatDefinition\\.group\\.groupNo').val();
		
			doGroupNoChanged(groupNo);
		});
		
		$("[id^='deleteHeaderBtn-']").click(function() {
			var idx = this.id.substring(16);
			var idName = "#tr-header-"+idx;
			$(idName).remove();
		});
		
		$("[id^='deleteItemBtn-']").click(function() {
			var idx = this.id.substring(14);
			var idName = "#tr-item-"+idx;
			$(idName).remove();
		});
		
		<c:if test="${null != actionBean.message}">
			$("#ajaxErrorMessageDiv").html('${actionBean.message}');
			$("#ajaxErrorMessageDiv" ).dialog({  
				title:'<%=UserUtil.getCurrentMenuItemName() %>' 
				,width: 600
				, resizable: false
				, modal: true
				, buttons: {
					Ok: function() {
						$( this ).dialog( "close" );
					}
				}
			});
		</c:if>
		
	});
	
	function doQueryAction(pageNumber)
	{
		if (null != pageNumber)
			$('#hidden\\.queryResult\\.pageNumber').val(pageNumber);
		$("#queryHiddenFrom").submit(); 
	}
	
	function addTableRow(jQtable, header){
	    jQtable.each(function(){
	        var $table = $(this);
	        //var newRowNum = $('tbody tr', this).length;
	        var newRowNum = parseInt($('tr:last td', this).html(),10);
	        
	        //2011/05/31 jeff Gu  start 修正新增完帳單項目設定後(圖一)，再去上傳檔案定義 刪除該項目的表單項目
	        //的資料(圖二)，之後再增加表單項目卻無新增資料!
	        if  (isNaN(newRowNum)){
	        	newRowNum=0;
	        }	
	        //2011/05/31 jeff Gu  end
	        // Number of td's in the last table row
	        var n = $('tr:last td', this).length;
	        var tds = '<tr id="tr-item-'+newRowNum+'">';
	        var idName = 'editItemColumnDefinitions';
	        if (header){
	        	tds = '<tr id="tr-header-'+newRowNum+'">';
	        	idName = 'editHeaderColumnDefinitions';
	        }
	        
	        tds += '<td>'+(newRowNum+1)+'</td>';
	        
	        tds += '<td>';
	        tds += '<input type="hidden" id="'+idName+'['+newRowNum+'].columnDefinitionPk" name="'+idName+'['+newRowNum+'].columnDefinitionPk" value="" />';
	        
	        tds += '<input type="hidden" id="'+idName+'['+newRowNum+'].header" name="'+idName+'['+newRowNum+'].header" value="'+ header +'" />';
	        //tds += '<input type="hidden" id="'+idName+'['+newRowNum+'].columnName" name="'+idName+'['+newRowNum+'].columnName" value="" size="10" maxlength="10"/>';
	        tds += '<input type="text" id="'+idName+'['+newRowNum+'].columnTitle" name="'+idName+'['+newRowNum+'].columnTitle" value="" size="10" maxlength="10"/>';       
	        tds += '</td>';
	        
	        tds += '<td>';
	        tds += '<select id="'+idName+'['+newRowNum+'].columnName" name="'+idName+'['+newRowNum+'].columnName">';
	        if (header){
	        	tds += '${actionBean.headerColumnsOptionsHtml}';
	        }
	        else {
	        	tds += '${actionBean.itemColumnsOptionsHtml}';
	        }
	        tds += '</select>';
	        tds += '</td>';
	        
	        tds += '<td>';
	        tds += '<input type="text" id="'+idName+'['+newRowNum+'].beginIndex" name="'+idName+'['+newRowNum+'].beginIndex" value="" size="3" maxlength="4"/>';
	        tds += '</td>';
	        
	        tds += '<td>';
	        tds += '<input type="text" id="'+idName+'['+newRowNum+'].endIndex" name="'+idName+'['+newRowNum+'].endIndex" value="" size="3" maxlength="4"/>';
	        tds += '</td>';
	        
	        tds += '<td>';
	        tds += '<select id="'+idName+'['+newRowNum+'].columnType" name="'+idName+'['+newRowNum+'].columnType">';
	        tds += '<option value="1" selected>字串</option>';
	        tds += '<option value="2">數值</option>';
	        tds += '<option value="3">日期</option>';
	        tds += '</select>';
	        tds += '</td>';
	        
	        tds += '<td>';
	        tds += '<input type="checkbox" id="'+idName+'['+newRowNum+'].required" name="'+idName+'['+newRowNum+'].required" />';
	        tds += '</td>';
	        
	        //tds += '<td>';
	        //tds += '<input type="checkbox" id="'+idName+'['+newRowNum+'].query" name="'+idName+'['+newRowNum+'].query" />';
	        //tds += '</td>';
	        
	        //tds += '<td>';
	        //tds += '<input type="checkbox" id="'+idName+'['+newRowNum+'].display" name="'+idName+'['+newRowNum+'].display"/>';
	        //tds += '</td>';
	        
	        //tds += '<td>';
	        //tds += '<input type="text" id="'+idName+'['+newRowNum+'].displayIdx" name="'+idName+'['+newRowNum+'].displayIdx" value="" size="2" maxlength="2"/>';
	        //tds += '</td>';

	        tds += '<td>';
	        tds += '</td>';
	        
	        tds += '</tr>';
	        
	        if($('tbody', this).length > 0){
	            $('tbody', this).append(tds);
	        }else {
	            $(this).append(tds);
	        }
	    });
	}
	
	
	function doQueryGroupAction(pageNumber)
	{
		$('#hidden\\.queryGroupResult\\.pageNumber').val(pageNumber);
		$("#queryGroupResultDiv").fadeTo("slow", 0.1);

		waitingDialog({});
		$.ajax({url : "<c:url value='/ajax/Soez9009.action'/>",
			async : true,
			type : 'POST',
			data : $("#queryGroupHiddenFrom").serialize(),
			dataType : 'html',
			success : function(data, textStatus, XMLHttpRequest){
					$("#queryGroupResultDiv").html(data);
				},
			error : function(XMLHttpRequest, textStatus, errorThrown){
				$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
				//$("#ajaxErrorMessageDiv" ).dialog( "destroy" );
				$("#ajaxErrorMessageDiv" ).dialog({  
					title:'系統錯誤' 
					,width: 600
					, resizable: false
					, modal: true
					, buttons: {
						Ok: function() {
							$( this ).dialog( "close" );
						}
					}
				});
				},
			complete: function(XMLHttpRequest, textStatus){
				if ($.browser.msie && /msie 6\.0/i.test(navigator.userAgent)){
					$("#findGroupDiv" ).dialog( "close" );
					$("#findGroupDiv" ).dialog( "open" );					
				}
				closeWaitingDialog();
				$("#queryGroupResultDiv").fadeTo("slow", 1);
			}
		});
	}
	
	function doGroupNoChanged(groupNo)
	{
		$("#qryFormatDefinition\\.group\\.groupName\\.span").html('');
		$('#queryResultDiv').html('');
		$('#qryFormatDefinition\\.formatDefinitionPk').find('option').remove().end()
			.append($("<option></option>").attr("value",""). text("-- 請選擇 --"));
		$('#groupNochangedHiddenFeedBackDiv').html('');
		$('#hidden\\.qryFormatDefinition\\.group\\.groupNo').val(groupNo);
		$('#hidden\\.qryFormatDefinition\\.group\\.groupNo2').val(groupNo);
		if (12 == $('#hidden\\.qryFormatDefinition\\.group\\.groupNo2').val().length){
			
			waitingDialog({});
			$.ajax({url : "<c:url value='/ajax/Soez9009.action'/>",
				async : true,
				type : 'POST',
				data : $("#groupNochangedHiddenFrom").serialize(),
				dataType : 'html',
				success : function(data, textStatus, XMLHttpRequest){
					var htmlData = data;
					$('#groupNochangedHiddenFeedBackDiv').html(htmlData);									
					
					$('#qryFormatDefinition\\.formatDefinitionPk').find('option').remove().end();
					$('#fmtSelectObjCache option').each(function(i){
						$('#qryFormatDefinition\\.formatDefinitionPk').append($(this));
					});
					
					$("#qryFormatDefinition\\.group\\.groupName\\.span").html($('#groupNameFeedBack').val());
					
					$('#groupNochangedHiddenFeedBackDiv').html('');
				
				},
				error : function(XMLHttpRequest, textStatus, errorThrown){
					$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
					$("#ajaxErrorMessageDiv" ).dialog({  
						title:'系統錯誤' 
						,width: 600
						, resizable: false
						, modal: true
						, buttons: {
							Ok: function() {
								$( this ).dialog( "close" );
							}
						}
					});
					},
				complete: function(XMLHttpRequest, textStatus){closeWaitingDialog();}
			});
		}
		
	}
	
	//-->
	</script>
</head>
<body>
<div id="mainAreaCT">
		<jsp:include page="/includes/path.jsp"/>
		<jsp:include page="/includes/subMenu.jsp"/>
		
	<div id="formatDefinitionDiv">
		<stripes:form id="qryFormatDefinitionForm" beanclass="com.feib.soeasy.action.Soez9009ActionBean" method="post"  onsubmit="javascript: return false;">
				
		<table id="queryForm">
			<tr>
				<th>業者代號<span id="mustKeyInStar">**</span></th>
				<td>
				<%if ( UserUtil.isBankGroup()){ %>				
					<div id="findGroupNoImg"><a href="javascript: void(0)" class="btnZoom">查詢</a></div>
					<stripes:text id="qryFormatDefinition.group.groupNo" name="qryFormatDefinition.group.groupNo" size="12" maxlength="12" />
					<span id="qryFormatDefinition.group.groupName.span"><c:out value="${actionBean.qryFormatDefinition.group.groupName }"/></span>
				 <%} else {%>
				  <input type="text" readonly="readonly" id="qryFormatDefinition.group.groupNo" name="qryFormatDefinition.group.groupNo" value="<%out.print(UserUtil.getUserGroup().getGroupNo());%>"/>				  
				  <span id="qryFormatDefinition.group.groupName.span"><%=UserUtil.getUserGroup().getGroupName()%></span>
				 <%}%> 														
					
				</td>
			</tr>
			<tr>
				<th>收款名稱<span id="mustKeyInStar">**</span></th>
				<td>
					<stripes:select id="qryFormatDefinition.formatDefinitionPk" name="qryFormatDefinition.formatDefinitionPk" >
						<stripes:option value="">--請選擇 --</stripes:option>
						<stripes:options-collection collection="${actionBean.formatDefinitionoOptions }" label="label" value="value"/>
					</stripes:select>
				</td>
			</tr>
			
			<tr>
				<td colspan="2" class="queryFunction">
					<stripes:button id="doQueryBtn" name="doQuery" value="查詢" class="formBtn"/>
				</td>
			</tr>
		</table>
		</stripes:form>
	</div><!-- end #formatDefinitionDiv -->
	
	<div id="queryHiddenFormDiv" style="display: none;">
		<stripes:form id="queryHiddenFrom" beanclass="com.feib.soeasy.action.Soez9009ActionBean" 
			method="post" onsubmit="javascript: waitingDialog({});">
			
			
			<stripes:hidden id="hidden.qryFormatDefinition.formatDefinitionPk" name="qryFormatDefinition.formatDefinitionPk"/>
			<stripes:hidden id="hidden.qryFormatDefinition.group.groupNo" name="qryFormatDefinition.group.groupNo"/>
			<stripes:hidden id="hidden.qryFormatDefinition.group.groupName" name="qryFormatDefinition.group.groupName"/>
			
			<stripes:hidden id="hidden.queryResult.pageNumber" name="queryResult.pageNumber" />
			
			<stripes:hidden id="hidden.doQueryBtn" name="doQuery" class="formBtn"/>
		</stripes:form>
	</div>
	
	<div id="groupNochangedHiddenFromDiv" style="display: none; ">
		<stripes:form id="groupNochangedHiddenFrom" beanclass="com.feib.soeasy.action.Soez9009ActionBean" 
			method="post" onsubmit="javascript: return false;">
			<stripes:hidden id="hidden.qryFormatDefinition.group.groupNo2" name="qryFormatDefinition.group.groupNo"/>
			<input type="hidden" id="method" name="doAjaxGroupNoChange"/>
		</stripes:form>
	</div>
	<dir id="groupNochangedHiddenFeedBackDiv" style="display: none;"></dir>
	
<div id="queryResultDiv">
	<c:if test="${null != actionBean.editFormatDefinition }">
		<stripes:form id="groupNochangedHiddenFrom" beanclass="com.feib.soeasy.action.Soez9009ActionBean"
			method="post" onsubmit="javascript: waitingDialog({});" >
		
		<input type="hidden" id="editFormatDefinition.formatDefinitionPk" name="editFormatDefinition.formatDefinitionPk" value="<c:out value="${actionBean.editFormatDefinition.formatDefinitionPk }" />" />
		<c:out value="${actionBean.editFormatDefinition.formatName }"></c:out>
		<table id="headerColumnDefinitions">
			<thead>
			<tr>
				<th colspan="11" >表頭欄位</th>
			</tr>              
			<tr>
				<th>序號</th>
				<th>欄位名稱</th>
				<th>對應欄位</th>
				<th>資料位置(起)</th>
				<th>資料位置(迄)</th>
				<th>欄位型態</th>
				<th>必要欄位</th>
				<!--  
				<th>設定查詢</th>
				<th>設定顯示</th>
				<th>顯示順序</th>
				-->
				<th></th>
            </tr>
            </thead>
            <tbody>
		<c:forEach items="${actionBean.editHeaderColumnDefinitions}" var="viewObj" varStatus="rowstat">
				<tr id="tr-header-${rowstat.index}">
					<td>${rowstat.index + 1 }</td>
					<td>
						<input type="hidden" id="editHeaderColumnDefinitions[${rowstat.index}].columnDefinitionPk" name="editHeaderColumnDefinitions[${rowstat.index}].columnDefinitionPk" value="<c:out value="${viewObj.columnDefinitionPk }" />" />
						<input type="hidden" id="editHeaderColumnDefinitions[${rowstat.index}].header" name="editHeaderColumnDefinitions[${rowstat.index}].header" value="true" />
						<input type="text" id="editHeaderColumnDefinitions[${rowstat.index}].columnTitle" name="editHeaderColumnDefinitions[${rowstat.index}].columnTitle" value="<c:out value="${viewObj.columnTitle }" />" size="10" maxlength="10"/>					
						
					</td>
					<td><select id="editHeaderColumnDefinitions[${rowstat.index}].columnName" 
						name="editHeaderColumnDefinitions[${rowstat.index}].columnName"
							<c:if test="${not viewObj.canModify }">disabled</c:if> >
							<option value="">--請選擇--</option>
							<c:forEach items="${actionBean.headerColumnsOptions}" var="optionObj" varStatus="optionRowstat">
								<option value="${ optionObj.columnName}" <c:if test="${optionObj.columnName eq viewObj.columnName}">selected</c:if>>${ optionObj.columnTitle}</option>
							</c:forEach>					
						</select>						
						<c:if test="${not viewObj.canModify }">
						<input type="hidden" id="editHeaderColumnDefinitions[${rowstat.index}].columnName.hidden" name="editHeaderColumnDefinitions[${rowstat.index}].columnName" value="<c:out value="${viewObj.columnName }" />" />
						</c:if>
					</td>
					<td>
						<input type="text" id="editHeaderColumnDefinitions[${rowstat.index}].beginIndex" 
							name="editHeaderColumnDefinitions[${rowstat.index}].beginIndex" 
							value="<c:out value="${viewObj.beginIndex }" />" size="3" maxlength="4"
							<c:if test="${not viewObj.cnaModifyLength }">readonly</c:if> />
					</td>
					<td>
						<input type="text" id="editHeaderColumnDefinitions[${rowstat.index}].endIndex" 
							name="editHeaderColumnDefinitions[${rowstat.index}].endIndex" 
							value="<c:out value="${viewObj.endIndex }" />" size="3" maxlength="4"
							<c:if test="${not viewObj.cnaModifyLength }">readonly</c:if> />
					</td>
					<td>
						<select id="editHeaderColumnDefinitions[${rowstat.index}].columnType" 
							name="editHeaderColumnDefinitions[${rowstat.index}].columnType"
							<c:if test="${not viewObj.canModify }">disabled</c:if> >
							<option value="1" <c:if test="${viewObj.columnType == 1}">selected</c:if>>字串</option>
							<option value="2" <c:if test="${viewObj.columnType == 2}">selected</c:if>>數值</option>
							<option value="3" <c:if test="${viewObj.columnType == 3}">selected</c:if>>日期</option>						
						</select>						
						<c:if test="${not viewObj.canModify }">
						<input type="hidden" id="editHeaderColumnDefinitions[${rowstat.index}].columnType.hidden" name="editHeaderColumnDefinitions[${rowstat.index}].columnType" value="<c:out value="${viewObj.columnType }" />" />
						</c:if>
					</td>
					<td>
						<input type="checkbox" id="editHeaderColumnDefinitions[${rowstat.index}].required" 
							name="editHeaderColumnDefinitions[${rowstat.index}].required" <c:if test="${viewObj.required}">checked</c:if>
							<c:if test="${not viewObj.canModify }">disabled</c:if> />						
						<c:if test="${not viewObj.canModify }">
						<input type="hidden" id="editHeaderColumnDefinitions[${rowstat.index}].required.hidden" name="editHeaderColumnDefinitions[${rowstat.index}].required" value="<c:out value="${viewObj.required }" />" />
						</c:if>
					</td>
<!--
					<td>
						<input type="checkbox" id="editHeaderColumnDefinitions[${rowstat.index}].query" name="editHeaderColumnDefinitions[${rowstat.index}].query" <c:if test="${viewObj.query}">checked</c:if>/>
					</td>
					<td>
						<input type="checkbox" id="editHeaderColumnDefinitions[${rowstat.index}].display" name="editHeaderColumnDefinitions[${rowstat.index}].display" <c:if test="${viewObj.display}">checked</c:if>/>
					</td>
					<td>
						<input type="text" id="editHeaderColumnDefinitions[${rowstat.index}].displayIdx" name="editHeaderColumnDefinitions[${rowstat.index}].displayIdx" value="<c:out value="${viewObj.displayIdx }" />" size="2" maxlength="2"/>
					</td>
-->
					<td>
						<c:if test="${viewObj.canDelete }">
						<input type="button" id="deleteHeaderBtn-${rowstat.index}" name="doDelete" value="刪除" />
						</c:if>
					</td>
				</tr>
		</c:forEach>
			</tbody>
			</table>
		
			<div align="center">
				<br/>
				<c:if test="${2 != actionBean.editFormatDefinition.formatType }">
					<input type="button" id="doAddHeaderColumnBtn" name="doAddHeaderColumn" value="新增表頭欄位"/>
				</c:if>
				<c:if test="${2 == actionBean.editFormatDefinition.formatType }">
					<input type="submit" id="doSaveColumnDefinitionBtn" name="doSaveColumnDefinition" value="確認"/>
					<input type="button" id="printBtn2" value="列印" />
				</c:if>
			</div>
			
<c:if test="${2 != actionBean.editFormatDefinition.formatType }">
			
			<table id="itemColumnDefinitions">
			<thead>		
			<tr>
				<th colspan="11" >表單項目</th>
			</tr>              
			<tr>
				<th>序號</th>
				<th>欄位名稱</th>
				<th>對應欄位</th>
				<th>資料位置(起)</th>
				<th>資料位置(迄)</th>
				<th>欄位型態</th>
				<th>必要欄位</th>
				<!--  
				<th>設定查詢</th>
				<th>設定顯示</th>
				<th>顯示順序</th>
				-->
				<th></th>
            </tr>
            </thead>
            <tbody>
		<c:forEach items="${actionBean.editItemColumnDefinitions}" var="viewObj" varStatus="rowstat">
				<tr id="tr-item-${rowstat.index}">
					<td>${rowstat.index + 1 }</td>
					<td>
						<input type="hidden" id="editItemColumnDefinitions[${rowstat.index}].columnDefinitionPk" name="editItemColumnDefinitions[${rowstat.index}].columnDefinitionPk" value="<c:out value="${viewObj.columnDefinitionPk }" />" />
						<input type="hidden" id="editItemColumnDefinitions[${rowstat.index}].header" name="editItemColumnDefinitions[${rowstat.index}].header" value="false" />						
						<input type="text" id="editItemColumnDefinitions[${rowstat.index}].columnTitle" name="editItemColumnDefinitions[${rowstat.index}].columnTitle" value="<c:out value="${viewObj.columnTitle }" />" size="10" maxlength="10"/>
					</td>
					<td>
						<select id="editItemColumnDefinitions[${rowstat.index}].columnName"
							name="editItemColumnDefinitions[${rowstat.index}].columnName"
							<c:if test="${not viewObj.canModify }">disabled</c:if> >
							<option value="">--請選擇--</option>
							<c:forEach items="${actionBean.itemColumnsOptions}" var="optionObj" varStatus="optionRowstat">
								<option value="${ optionObj.columnName}" <c:if test="${optionObj.columnName eq viewObj.columnName}">selected</c:if>>${ optionObj.columnTitle}</option>
							</c:forEach>					
						</select>						
						<c:if test="${not viewObj.canModify }">
						<input type="hidden" id="editItemColumnDefinitions[${rowstat.index}].columnName.hidden" name="editItemColumnDefinitions[${rowstat.index}].columnName" value="<c:out value="${viewObj.columnName }" />" />
						</c:if>
					</td>
					<td>
						<input type="text" id="editItemColumnDefinitions[${rowstat.index}].beginIndex" 
							name="editItemColumnDefinitions[${rowstat.index}].beginIndex" 
							value="<c:out value="${viewObj.beginIndex }" />" size="3" maxlength="4" 
							<c:if test="${not viewObj.cnaModifyLength }">readonly</c:if> />
					</td>
					<td>
						<input type="text" id="editItemColumnDefinitions[${rowstat.index}].endIndex" 
							name="editItemColumnDefinitions[${rowstat.index}].endIndex" 
							value="<c:out value="${viewObj.endIndex }" />" size="3" maxlength="4"
							<c:if test="${not viewObj.cnaModifyLength }">readonly</c:if> />
					</td>
					<td>
						<select id="editItemColumnDefinitions[${rowstat.index}].columnType" 
							name="editItemColumnDefinitions[${rowstat.index}].columnType" 
							<c:if test="${not viewObj.canModify }">disabled</c:if> >
							<option value="1" <c:if test="${viewObj.columnType == 1}">selected</c:if>>字串</option>
							<option value="2" <c:if test="${viewObj.columnType == 2}">selected</c:if>>數值</option>
							<option value="3" <c:if test="${viewObj.columnType == 3}">selected</c:if>>日期</option>						
						</select>
						
						<c:if test="${not viewObj.canModify }">
						<input type="hidden" id="editItemColumnDefinitions[${rowstat.index}].columnType.hidden" name="editItemColumnDefinitions[${rowstat.index}].columnType" value="<c:out value="${viewObj.columnType }" />" />
						</c:if>
					</td>
					<td>
						<input type="checkbox" id="editItemColumnDefinitions[${rowstat.index}].required" 
							name="editItemColumnDefinitions[${rowstat.index}].required" <c:if test="${viewObj.required}">checked</c:if>
							<c:if test="${not viewObj.canModify }">disabled</c:if> />						
						<c:if test="${not viewObj.canModify }">
						<input type="hidden" id="editItemColumnDefinitions[${rowstat.index}].required.hidden" name="editItemColumnDefinitions[${rowstat.index}].required" value="<c:out value="${viewObj.required }" />" />
						</c:if>
					</td>
<!--  
					<td>
						<input type="checkbox" id="editItemColumnDefinitions[${rowstat.index}].query" name="editItemColumnDefinitions[${rowstat.index}].query" <c:if test="${viewObj.query}">checked</c:if>/>
					</td>
					<td>
						<input type="checkbox" id="editItemColumnDefinitions[${rowstat.index}].display" name="editItemColumnDefinitions[${rowstat.index}].display" <c:if test="${viewObj.display}">checked</c:if>/>
					</td>
					<td>
						<input type="text" id="editItemColumnDefinitions[${rowstat.index}].displayIdx" name="editItemColumnDefinitions[${rowstat.index}].displayIdx" value="<c:out value="${viewObj.displayIdx }" />" size="2" maxlength="2"/>
					</td>
-->
					<td>
						<c:if test="${viewObj.canDelete }">
						<input type="button" id="deleteItemBtn-${rowstat.index}" name="doDelete" value="刪除" />
						</c:if>
					</td>
				</tr>
		</c:forEach>
			</tbody>		
		</table>
		
		
		<div align="center">
			<br/>
			<input type="button" id="doAddItemColumnBtn" name="doAddItemColumn" value="新增表單項目"/>
			<input type="submit" id="doSaveColumnDefinitionBtn" name="doSaveColumnDefinition" value="確認"/>
			<input type="button" id="printBtn2" value="列印" />
		</div>
</c:if>

		</stripes:form>
	</c:if>
</div>

	<div id="findGroupDiv" style="display: none;">
		<div id="queryGroupDiv">
		<table>
			<tr>
				<th>業者代號</th>
				<td><input id="qryGroup.groupNo" type="text" size="12" maxlength="12" /> </td>
			</tr>
			<tr>
				<th>名稱</th>
				<td><input id="qryGroup.groupName" type="text" size="20" /></td>
			</tr>
			<tr>
				<td colspan="2" class="queryFunction">
					<input type="button" value="查詢" id="doAjaxQueryGroupsBtn"/>
					<input type="button" value="離開" id="doAjaxCloseGroupsBtn"/>
				</td>
			</tr>
		</table>
		</div>
		<div id="queryGroupResultDiv" style="display: none;">
		</div>
	</div>
	<div id="queryGroupHiddenFormDiv" style="display: none; ">
		<stripes:form id="queryGroupHiddenFrom" beanclass="com.feib.soeasy.action.Soez9009ActionBean" 
			method="post" onsubmit="javascript: return false;">
			<stripes:hidden id="hidden.qryGroup.groupName" name="qryGroup.groupName"/>
			<stripes:hidden id="hidden.qryGroup.groupNo" name="qryGroup.groupNo"/>
			<stripes:hidden id="hidden.queryGroupResult.pageNumber" name="queryGroupResult.pageNumber" />			
			<input type="hidden" id="method" name="doAjaxQueryGroups"/>
		</stripes:form>
	</div>
	
	
		
	<!-- Message -->
	<div id="ajaxErrorMessageDiv" style="display: none;"></div>
	
</div>
</body>
</html>